<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Class CreateRatingSubitemsTable.
 */
class CreateRatingSubitemsTable extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('rating_subitems', function (Blueprint $table) {
			$table->increments('id');
			$table->unsignedInteger('category_id')->index();
			$table->string('subitem_name')->comment('具体评分项目名');
			$table->unsignedInteger('subitem_score')->comment('该具体项目分值');
			$table->unsignedInteger('default_score')->comment('该具体项目默认分值');
			$table->unsignedInteger('column_width')->default(20)->comment('该具体项目列宽');
			$table->timestamps();
		});

		$sql = <<<SQL
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '无乱拉乱接电线现象', 15 FROM rating_categories WHERE category_name = '安全管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '严禁使用大功率电器、存放易燃易爆等违禁用品', 15 FROM rating_categories WHERE category_name = '安全管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '阳台无悬空放置物品', 10 FROM rating_categories WHERE category_name = '安全管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '公共设施(床、窗、柜子等)是否完整，有无拆卸、调换', 15 FROM rating_categories WHERE category_name = '公共设施管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '公共设施(门、锁、排水管等)有无损坏', 15 FROM rating_categories WHERE category_name = '公共设施管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '宿舍干净、地面、物品摆放整洁', 10 FROM rating_categories WHERE category_name = '文明卫生管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '宿舍安宁、团结，无打架斗殴', 10 FROM rating_categories WHERE category_name = '文明卫生管理';
INSERT INTO rating_subitems (category_id, subitem_name, subitem_score) SELECT id, '宿舍无饲养家禽、宠物', 10 FROM rating_categories WHERE category_name = '文明卫生管理';
SQL;
		DB::unprepared($sql);
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('rating_subitems');
	}
}
